package com.hinner.controller;

import com.hinner.common.Result;
import com.hinner.entity.Chinas;
import com.hinner.entity.dto.UserDTO;
import com.hinner.entity.vo.UserVO;
import com.hinner.service.ChinasService;
import com.hinner.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chinas")
public class ChinasController {
    @Autowired
    private ChinasService chinasService;

    //查询所有地区信息：省-市-县
    @GetMapping("/getRegions")
    public Result getRegions(){
        List<Chinas> res = chinasService.getRegions();
        return Result.success(res);
    }

    /**
     * 给一个code查询出父行政区和子行政区
     * @param code
     * @return
     */
    @GetMapping("/{code}")
    public Result getRegionByCode(@PathVariable("code") String code){
        return Result.success(chinasService.getRegionByCode(code));
    }

    /**
     * 根据城市code，查询城市名
     * @param cityCode
     * @return
     */
    @GetMapping("/getRegionNameByCode/{cityCode}")
    public Result getRegionNameByCode(@PathVariable("cityCode") String cityCode){
        return Result.success(chinasService.getRegionNameByCode(cityCode));
    }


    /**
     * 给一个code查询出父行政区和子行政区
     * @param code
     * @return
     */
    @GetMapping("/wholeName/{code}")
    public Result wholeNameByCode(@PathVariable("code") String code){
        return Result.success(chinasService.wholeNameByCode(code));
    }

    @GetMapping("/regions")
    public Result regions(){
        return Result.success(chinasService.regions());
    }

    //根据省code得到下面所有的子code
    @GetMapping("/childRegions/{id}")
    public Result childRegions(@PathVariable("id") String id){
        return Result.success(chinasService.getChildRegions(id));
    }
}

